FROM alpinelinux/golang as builder

WORKDIR /app
RUN chmod 777 .
COPY . .
RUN GOPROXY=https://goproxy.io,direct CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o app

FROM node:latest as ui
WORKDIR /ui
RUN npm config set registry https://registry.npmmirror.com/
COPY --from=builder /app/my-ui my-ui
WORKDIR /ui/my-ui
RUN npm install
RUN npm run build

FROM alpine:latest
# 使用阿里云的镜像源替换默认的官方源
RUN echo "https://mirrors.aliyun.com/alpine/v3.14/main" > /etc/apk/repositories && \
    echo "https://mirrors.aliyun.com/alpine/v3.14/community" >> /etc/apk/repositories \
RUN apk update
WORKDIR /app
COPY --from=builder /app/app app
COPY --from=builder /app/settings.yml settings.yml
COPY --from=ui /ui/my-ui/dist my-ui
ENTRYPOINT ["./app"]
